import './libs/weapp-adapter';
import JsLogic, {readFile} from "./runtime/jslogic";
import init, {create_new_info, RsCore} from "./libs/petlib";
const wasmPet = init("js/libs/petlib_bg.wasm")
/**
 * 游戏主函数
 */

export default class Main {
    constructor() {
        var jsLogic = new JsLogic();
        wx.getStorage({
            key: "info",
            encrypt: false,
            success: res => {
                console.log("xxxxx getInfo suc")
                jsLogic.info = res.data
                jsLogic.isNewUser = false
                jsLogic.bGetInfoDone = true
                jsLogic.line = jsLogic.info.base.travel_line
                this.loadSub();
            },
            fail: () => {
                console.log("xxxxx getInfo fail")
                jsLogic.isNewUser = true
                jsLogic.bGetInfoDone = true
                // debugger
                this.loadSub();
            }
        })
        // loadTask

    }
    loadSub(){
        wx.loadSubpackage({
            complete: function (res) {
                console.log(`分包--complete: ${res}`)
            },
            fail: function (res) {
                console.log(`分包--fail: ${res}`)
            },
            name: 'subPackage',
            success: function (res) {

                let router = require('./sub/game'),
                    options = wx.getLaunchOptionsSync(),
                    query = options.query;

                router.constructor();
                console.log(`分包--success: ${res}`)

            },
        }).onProgressUpdate(res => {
            console.log('分包--下载进度', res.progress)
            console.log('分包--已经下载的数据长度', res.totalBytesWritten)
            console.log('分包--预期需要下载的数据总长度', res.totalBytesExpectedToWrite)
        })

    }



}
